<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Dcat\Admin\Traits\HasDateTimeFormatter;

class User extends Authenticatable implements JWTSubject
{
    use HasDateTimeFormatter,HasApiTokens, HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'avatar',
        'nickname',
        'parent_id',
        'sex',
        'points',
        'phone',
        'user_title_id',
        'balance',
        'continuous_sign_num',
        'total_points',
        'openid',
        'wx_app_openid',
        'qq_openid',
        'wx_min_openid',
        'min_qrcode'
    ];

    protected $attributes = [
        'avatar' => '',
        'nickname' => '',
        'openid' => '',
        'parent_id' => 0,
        'points' => 0,
        'sex' => 1,
        'phone' => '',
        'user_title_id' => 1,
        'balance' => 0,
        'continuous_sign_num' => 0,
        'total_points' => 0,
        'min_qrcode' => ''
    ];


    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }

    public function title()
    {
        return $this->belongsTo(UserTitle::class,'user_title_id');
    }

    public function firm()
    {
        return $this->hasOne(Firm::class,'user_id');
    }

    public function identity()
    {
        return $this->hasOne(UserIdentity::class,'user_id','id');
    }

    public function follow()
    {
        return $this->hasMany(UserFollow::class,'user_id');
    }

    public function fans()
    {
        return $this->hasMany(UserFollow::class,'friend_id');
    }

    public function alike()
    {
        return $this->hasMany(UserLikeArticle::class,'user_id');
    }

    public function like()
    {
        return $this->hasMany(UserLikeCourse::class,'user_id');
    }

    public function member()
    {
        return $this->hasOne(UserMember::class,'user_id','id');
    }

    public function article()
    {
        return $this->hasOne(Article::class,'user_id');
    }


    public function auth()
    {
        return $this->hasOne(UserAuth::class,'user_id','id');
    }
}
